package view;

import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;

import model.SimulationSettings;



public class MenuFrame extends JFrame{
	
	public JPanel mainPanel, orderTypePanel, currentPricePanel, interestPanel, strikePricePanel, timeMaturityPanel, feesPanel, volatilityPanel, stepsPanel, simulationPanel, startPanel;
	//Labels that will be used to explain input fields.
	public JLabel orderTypeLabel, currentPriceLabel, strikePriceLabel, timeMaturityLabel, interestLabel, feesLabel, volatilityLabel, stepsLabel, simulationLabel;

	//input for order type
	public JComboBox<String> orderTypeCombo;
	
	//input fields for numerical options
	public JSpinner currentPriceSpin, strikePriceSpin, timeMaturitySpin, interestSpin, feesSpin, volatilitySpin, stepsSpin, simulationSpin;
	
	public JButton start;
	
	public MenuFrame()
	{

		initComponents();
		
		//Creating the JSpinners
		
		SimulationSettings defaultSettings = new SimulationSettings();
		
		SpinnerModel currentPriceModel = new SpinnerNumberModel(defaultSettings.currentPrice, 0, 100, 1);		
		currentPriceSpin = new JSpinner(currentPriceModel);		
		SpinnerModel strikePriceModel = new SpinnerNumberModel(defaultSettings.strikePrice, 0, 100, 1);		
		strikePriceSpin = new JSpinner(strikePriceModel);		
		SpinnerModel timeMaturityModel = new SpinnerNumberModel(defaultSettings.timeMaturity, 0, 50, 0.5);
		timeMaturitySpin = new JSpinner(timeMaturityModel);		
		SpinnerModel interestModel = new SpinnerNumberModel(defaultSettings.interest, 0, 10, 0.005);
		interestSpin = new JSpinner(interestModel);		
		SpinnerModel feesModel = new SpinnerNumberModel(defaultSettings.fees, 0, 10, 0.005);
		feesSpin = new JSpinner(feesModel);		
		SpinnerModel volatilityModel = new SpinnerNumberModel(defaultSettings.volatility, 0, 10, 0.05);
		volatilitySpin = new JSpinner(volatilityModel);		
		SpinnerModel stepsModel = new SpinnerNumberModel(defaultSettings.steps, 1, 1000, 1);
		stepsSpin = new JSpinner(stepsModel);		
		SpinnerModel simulationModel = new SpinnerNumberModel(defaultSettings.simulation, 1, 100000, 10);
		simulationSpin = new JSpinner(simulationModel);
		
		orderTypeCombo.setSelectedItem("Call");
		
		packLayout();

		
	}
	
	public MenuFrame(SimulationSettings settings)
	{
		initComponents();
		
		//Creating the JSpinners
		
		SpinnerModel currentPriceModel = new SpinnerNumberModel(settings.currentPrice, 0, 100, 1);		
		currentPriceSpin = new JSpinner(currentPriceModel);		
		SpinnerModel strikePriceModel = new SpinnerNumberModel(settings.strikePrice, 0, 100, 1);		
		strikePriceSpin = new JSpinner(strikePriceModel);		
		SpinnerModel timeMaturityModel = new SpinnerNumberModel(settings.timeMaturity, 0, 50, 0.5);
		timeMaturitySpin = new JSpinner(timeMaturityModel);		
		SpinnerModel interestModel = new SpinnerNumberModel(settings.interest, 0, 10, 0.005);
		interestSpin = new JSpinner(interestModel);		
		SpinnerModel feesModel = new SpinnerNumberModel(settings.fees, 0, 10, 0.005);
		feesSpin = new JSpinner(feesModel);		
		SpinnerModel volatilityModel = new SpinnerNumberModel(settings.volatility, 0, 10, 0.05);
		volatilitySpin = new JSpinner(volatilityModel);		
		SpinnerModel stepsModel = new SpinnerNumberModel(settings.steps, 1, 1000, 1);
		stepsSpin = new JSpinner(stepsModel);		
		SpinnerModel simulationModel = new SpinnerNumberModel(settings.simulation, 10, 100000000, 10);
		simulationSpin = new JSpinner(simulationModel);
		
		orderTypeCombo.setSelectedItem(settings.orderType);
		
		packLayout();
		
		
	}
	
	private void initComponents()
	{
		mainPanel = new JPanel();
		orderTypePanel = new JPanel();
		currentPricePanel = new JPanel();
		strikePricePanel = new JPanel();
		interestPanel = new JPanel();
		timeMaturityPanel = new JPanel();
		feesPanel = new JPanel();
		volatilityPanel = new JPanel();
		stepsPanel = new JPanel();
		simulationPanel = new JPanel();
		startPanel = new JPanel();
		
		
		orderTypeLabel = new JLabel("Order Type :");
		orderTypeCombo = new JComboBox<String>();

		currentPriceLabel = new JLabel("Current Price :");
		strikePriceLabel = new JLabel("Strike Price :");
		timeMaturityLabel = new JLabel("Time to maturity :");
		interestLabel = new JLabel("Interest Rate :");
		feesLabel = new JLabel("Fees :");
		volatilityLabel = new JLabel("Volatility :");
		stepsLabel = new JLabel("Steps :");
		simulationLabel = new JLabel("Simulations :");
		
		start = new JButton("Start");
		
		
		//Setting comboBox options
		orderTypeCombo.addItem("Call");
		orderTypeCombo.addItem("Put");
		
	}
	private void packLayout()
	{
		//Adding components to Panels
		
		orderTypePanel.add(orderTypeLabel);
		orderTypePanel.add(orderTypeCombo);		
		currentPricePanel.add(currentPriceLabel);
		currentPricePanel.add(currentPriceSpin);		
		strikePricePanel.add(strikePriceLabel);
		strikePricePanel.add(strikePriceSpin);		
		timeMaturityPanel.add(timeMaturityLabel);
		timeMaturityPanel.add(timeMaturitySpin);		
		interestPanel.add(interestLabel);
		interestPanel.add(interestSpin);		
		feesPanel.add(feesLabel);
		feesPanel.add(feesSpin);		
		volatilityPanel.add(volatilityLabel);
		volatilityPanel.add(volatilitySpin);		
		stepsPanel.add(stepsLabel);
		stepsPanel.add(stepsSpin);		
		simulationPanel.add(simulationLabel);
		simulationPanel.add(simulationSpin);
		startPanel.add(start);
	
		
		
		
		
		//Setting dimensions
		int width = 250, height = 400;
		Dimension dim = new Dimension(width - 10, 40);
		orderTypePanel.setPreferredSize(dim);
		currentPricePanel.setPreferredSize(dim);
		strikePricePanel.setPreferredSize(dim);
		timeMaturityPanel.setPreferredSize(dim);
		interestPanel.setPreferredSize(dim);
		feesPanel.setPreferredSize(dim);
		volatilityPanel.setPreferredSize(dim);
		stepsPanel.setPreferredSize(dim);
		simulationPanel.setPreferredSize(dim);
		startPanel.setPreferredSize(dim);
		
		//Setting dimensions
		dim.height=25;
		dim.width= 100;
		currentPriceSpin.setPreferredSize(dim);
		strikePriceSpin.setPreferredSize(dim);
		timeMaturitySpin.setPreferredSize(dim);
		interestSpin.setPreferredSize(dim);
		feesSpin.setPreferredSize(dim);
		volatilitySpin.setPreferredSize(dim);
		stepsSpin.setPreferredSize(dim);
		simulationSpin.setPreferredSize(dim);
		
		
		// Packing Panels
		mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
		mainPanel.add(orderTypePanel);
		mainPanel.add(currentPricePanel);
		mainPanel.add(strikePricePanel);
		mainPanel.add(timeMaturityPanel);
		mainPanel.add(interestPanel);
		mainPanel.add(feesPanel);
		mainPanel.add(volatilityPanel);
		mainPanel.add(stepsPanel);
		mainPanel.add(simulationPanel);
		mainPanel.add(startPanel);
		
		// Final display instructions
		
		this.setTitle("Monte Carlo");
		this.setContentPane(mainPanel);
		this.setSize(width, height);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setVisible(true);	
		
	}
	
	
	
}
